package com.vancouver.knows.business.tracker;

import android.util.Log;

import com.pangu.task.IResultReceiver;
import com.pangu.task.OperateResult;
import com.vancouver.knows.business.BSharedPrefManager;
import com.vancouver.knows.business.BusinessModule;
import com.vancouver.knows.business.bean.EditUserInfo;
import com.vancouver.knows.business.bean.UserInfo;

/**
 * Created by Chris Li on 2016-07-22.
 */
public class UserEditProfileTracker extends ABInvokeTracker {

    public UserEditProfileTracker(BusinessModule module, IResultReceiver resultReceiver) {
        super(module, resultReceiver);
    }

    @Override
    public String TAG() {
        return UserEditProfileTracker.class.getSimpleName();
    }

    @Override
    public void handleResult(OperateResult result) {
        EditUserInfo editUserInfo = (EditUserInfo) result.getResultData();
        if (editUserInfo == null) {
            return;
        }

        BSharedPrefManager sharedPrefManager = (BSharedPrefManager) imContext.getSharedPrefManager();
        sharedPrefManager.saveUserName(editUserInfo.getDisplayName());
        sharedPrefManager.saveRegisterType(editUserInfo.getRegisterType());
        UserInfo.UserMeta userMeta = editUserInfo.getUserMeta();
        UserInfo.UserMeta localUserMeta = sharedPrefManager.getUserMeta();
        localUserMeta.setPhone(userMeta.getPhone());
        localUserMeta.setEmail(userMeta.getEmail());
        localUserMeta.setCity(userMeta.getCity());
        sharedPrefManager.saveUserMeta(localUserMeta);
    }
}
